Page({
  onShareAppMessage () {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index',
      imageUrl: this.data.url
    }
  },
  onLoad ({ id }) {
    this.id = id
  },
  data: {
    url: '',
    houseInfo: ''
  },
  onShow () {
    this.getImg()
  },
  async getImg () {
    const { data } = await wx.http.get(`/visitor/${this.id}`)
    this.setData({
      url: data.url,
      houseInfo: data.houseInfo
    })
  },
  async saveQRCode () {
    try {
      // 读取图片信息
      // 注意配置域名：https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com
      const { path } = await wx.getImageInfo({
        // 二维码的图片路径
        src: this.data.url
      })
      // 保存图片到相册
      wx.saveImageToPhotosAlbum({ filePath: path })
    } catch (err) {
      wx.utils.toast('保存图片失败，稍后重试!')
    }
  }
})
